/***************************************************************************************
Firm-embedded productivity and cross-country income differences
Alviarez, Cravino and Ramondo
Journal of Political Economy (2022)

Program: figure_01_market_share.do
Date: October 2022

Description: Reproduces Figure 1: Market shares of foreign MNE affiliates, relative to France.

*****************************************************************************************/

*-------------------------------------------------------------------------------
global typeden=1
include "set_directories.do"
set memory 64g
global lf "LF"

*Log
cap log close
log using "${clogs}/figure_01_market_share.log",replace
*-------------------------------------------------------------------------------



*Figure 1: MNCs market share differences by income per capita of the location country (all economy)
*-------------------------------------------------------
clear all
use "${data}/estimates_agg_naics_sales_s1_base_woparent.dta", clear

local grvar0 "gdp_pw_ppp" 
local grvar1 ""	
local rr ""
local var3 "A"
local yy "2016"
merge m:1 year isocode type using "${data}/aggregates_tfp_lp_klems_agg.dta" 
drop if _merge==2
drop _merge
keep if year==`yy'

gen mkt_share=exp(D_A)
local LHS1 mkt_share
local RHS ln_`grvar0'
sum `LHS1' `RHS'  
local xtitle "Relative output per worker"

reg `LHS1' `RHS'
mat b = e(b)
mat V = e(V)
global c1: display %-03.2fc round(b[1,1],0.01)
global se1: display %-03.2fc round(sqrt(V[1,1]),0.01)

local xlab ""
local xlab `xlab' -1.098622289 "1/3"
local xlab `xlab' -0.693147289 "1/2"
local xlab `xlab' -0.287672289 "2/3"
local xlab `xlab' -0.000000000 "1"
local xlab `xlab' 0.117802711 " "
global opt1 msymbol(circle) mlabel(isocode) mlabcolor(blue) msize(small) mlabsize(small)

two (scatter `LHS1' `RHS', sort $opt1  mcolor(blue)), ysc(log) ylabel(0.01 1 2 4 8 16, format(%5.0f) labsize(medlarge)) xlabel(`xlab', format(%5.1f) labsize(medlarge)) ///
	title("`title'", size(small))  ytitle("", size(medlarge)) xtitle("`xtitle'", size(medium)) graphregion(fcolor(white) lcolor(white)) legend(off) 

graph export "${rmain}/fig_01.pdf", replace
	
	
	

